﻿using System.Linq.Expressions;

namespace ZeroSum.Extend.EFCore.MySql.Extensions;

/// <summary>
///     linq查询扩展
/// </summary>
public static class QueryableExtensions
{
    /// <summary>
    ///     条件查询
    /// </summary>
    /// <param name="query">源数据</param>
    /// <param name="condition">A boolean value</param>
    /// <param name="predicate">Predicate to filter the query</param>
    /// <returns>Filtered or not filtered query based on <paramref name="condition" /></returns>
    public static IQueryable<T> WhereIf<T>(this IQueryable<T> query, bool condition,
        Expression<Func<T, bool>> predicate)
    {
        return condition ? query.Where(predicate) : query;
    }
}